package graphics 
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.geom.Point;
	import graphics.IGraphic;
	
	/**
	 * ...
	 * @author Gareth Williams
	 */
	public class Square extends Sprite implements IGraphic
	{
		private var _width:int;
		private var _height:int;
		
		public function Square(colour:uint, _width:int, _height:int) 
		{
			//prevent a bug where an extra pixel width is introduced every time
			//the player is drawn based on sprite width and height by storing 
			//required width and height
			this._width = _width;
			this._height = _height;
			draw(colour, _width, _height);
		}
		private function draw(colour:uint, _width:int, _height:int):void
		{
			var gfx:Graphics = this.graphics;
			gfx.clear();
			gfx.beginFill(colour, 1);
				gfx.drawRect(-_width*0.5, -_height*0.5, _width, _height);
			gfx.endFill();
			gfx.lineStyle(1, 0xFFFFFF, 1);
				gfx.moveTo( -_width * 0.5, -_height * 0.5);
				gfx.lineTo(_width * 0.5, 0);
				gfx.lineTo( -_width * 0.5, _height * 0.5);
		}
		
		/* INTERFACE Graphics.IGraphic */
		
		public function move(position:Point):void 
		{
			this.x = position.x;
			this.y = position.y;
		}
		public function rotate(rotation:Number):void 
		{
			this.rotation = 180 / Math.PI * rotation;//bloody annoying rad to deg
		}
		public function doHitAnimation():void 
		{
			this.draw(Math.random() * 0xFFFFFF, _width, _height);
		}
		public function doDeathAnimation():void 
		{
			this.draw(0x303030, _width, _height);
		}
		public function doHealthAnimation(percentHealthRemaining:int):void 
		{
			//this.alpha = 0.01 * percentHealthRemaining;
		}
		public function updateAnimation():void
		{
			//stub...
		}
	}
}
